package com.portme.client.pages.widgets;

import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Label;
import com.portme.client.StaticFactory;
import com.portme.client.interfaces.Observer;
import com.portme.shared.ClientPost;

/**
 * PostLink represents a link displayed in Sidebar on every tab.
 * {themename}-single-post-link needs to be defined for every theme.
 */
public class PostLink extends Label implements Observer{
	
	private String theme;
	
//	private ClientPost post;
	
	/*private ClickHandler clickHandler = new ClickHandler() {
		
		@Override
		public void onClick(ClickEvent event) {
			
		}
	};*/
	
	public PostLink(ClientPost post, ClickHandler clickHandler) {
		super(post.getTitle());
//		this.post = post;
		this.theme = StaticFactory.getInstance().getTheme();
		addStyleName(this.theme+"-single-post-link");
		addClickHandler(clickHandler);
		StaticFactory.getInstance().observeTheme(this);
	}

	@Override
	public void notifyMe(Object arg) {
		String newTheme = (String)arg;
		if(newTheme != null) {
			removeStyleName(this.theme+"-single-post-link");
			addStyleName(newTheme+"-single-post-link");
			this.theme = newTheme;
		}
	}
	
	public void select() {
		addStyleName(this.theme+"-single-post-link-selected");
	}
	
	public void deselect() {
		removeStyleName(this.theme+"-single-post-link-selected");
	}
}
